package xmlMapping;

import xmlMapping.lts.InstrumentPoolRecord;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import java.util.List;

public class MainSelect {
    private static long i = System.currentTimeMillis();

    public static void main(String[] args) {

        Configuration cfg = new Configuration();

        SessionFactory sf = cfg.configure().buildSessionFactory();
        Session session = sf.openSession();
        try {
            List<InstrumentPoolRecord> list = session.createCriteria(InstrumentPoolRecord.class).list();
            Transaction tx = session.beginTransaction();
            /*for (InstrumentPoolRecord record : list) {
                System.out.println(record.getAccountPoolHeldMap());
                if (!record.getAccountPoolHeldMap().isEmpty()) {
                    record.getAccountPoolHeldMap().clear();
                    session.saveOrUpdate(record);
                    System.out.println(record.getAccountPoolHeldMap());
                }
            }*/
            InstrumentPoolRecord record = list.stream()
                    .filter(i -> "POS1-20180110-153444-601-1586".equals(i.getInstrumentPoolId()))
                    .findFirst().get();
            System.out.println(record);
            System.out.println(record.getAccountPoolHeldMap());


            //tx.commit();
            //System.out.println("done");

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            session.close();
        }
    }

    public static String genNext() {
        return i++ + "";
    }
}
